package com.collect.zambia.zhiAdater.zhiScriptLib;

import android.text.TextUtils;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.collect.zambia.R;
import com.collect.zambia.zhiBean.zhiReceive.ZHIRScriptLibEntity;

public class ZHIScriptLibAdjuster extends BaseQuickAdapter<ZHIRScriptLibEntity, BaseViewHolder> {
    private String mType;

    public ZHIScriptLibAdjuster() {
        super(R.layout.item_script_lib_list, null);
    }

    public ZHIScriptLibAdjuster(String type) {
        super(R.layout.item_script_lib_com_list, null);
        this.mType = type;
    }

    private OnScriptLibItemClickListener mOnScriptLibItemClickListener;

    @Override
    protected void convert(BaseViewHolder helper, final ZHIRScriptLibEntity zhirScriptLibEntity) {

        if (TextUtils.isEmpty(mType)) {
            helper.setText(R.id.tv_slib_title, helper.getAdapterPosition() + 1 + "、" + zhirScriptLibEntity.getTitle());
            helper.setText(R.id.tv_slib_detail, zhirScriptLibEntity.getContent());

            helper.addOnClickListener(R.id.tv_slib_title);
            helper.getView(R.id.tv_slib_title).setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View view) {
                    if (mOnScriptLibItemClickListener != null) {
                        mOnScriptLibItemClickListener.OnItemClick(zhirScriptLibEntity.getTitle());
                    }

                    TextView tv_slib_detail = helper.getView(R.id.tv_slib_detail);
                    tv_slib_detail.setVisibility(tv_slib_detail.getVisibility() == View.GONE ? View.VISIBLE : View.GONE);

                    ImageView iv_slib_ext = helper.getView(R.id.iv_slib_ext);
                    iv_slib_ext.setImageResource(tv_slib_detail.getVisibility() == View.GONE ? R.drawable.cf_ic_cf_37 : R.drawable.ct_ic_ct_107);
                }
            });

            helper.addOnClickListener(R.id.iv_slib_ext);
            helper.getView(R.id.iv_slib_ext).setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View view) {
                    if (mOnScriptLibItemClickListener != null) {
                        mOnScriptLibItemClickListener.OnItemClick(zhirScriptLibEntity.getTitle());
                    }

                    TextView tv_slib_detail = helper.getView(R.id.tv_slib_detail);
                    tv_slib_detail.setVisibility(tv_slib_detail.getVisibility() == View.GONE ? View.VISIBLE : View.GONE);

                    ImageView iv_slib_ext = helper.getView(R.id.iv_slib_ext);
                    iv_slib_ext.setImageResource(tv_slib_detail.getVisibility() == View.GONE ? R.drawable.cf_ic_cf_37 : R.drawable.ct_ic_ct_107);
                }
            });
        } else {
            helper.setText(R.id.tv_slib_title, zhirScriptLibEntity.getTitle());
            helper.setText(R.id.tv_slib_detail, zhirScriptLibEntity.getContent());

            helper.addOnClickListener(R.id.tv_slib_title);
            helper.getView(R.id.tv_slib_title).setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View view) {
                    if (mOnScriptLibItemClickListener != null) {
                        mOnScriptLibItemClickListener.OnItemClick(zhirScriptLibEntity.getTitle());
                    }

                    TextView tv_slib_detail = helper.getView(R.id.tv_slib_detail);
                    tv_slib_detail.setVisibility(tv_slib_detail.getVisibility() == View.GONE ? View.VISIBLE : View.GONE);
                }
            });
        }
    }

    public void setOnScriptLibItemClickListener(OnScriptLibItemClickListener optionClickListener) {
        this.mOnScriptLibItemClickListener = optionClickListener;
    }

    public interface OnScriptLibItemClickListener {
        void OnItemClick(String title);
    }
}
